//
//  GRCouseFeeMainVC.m
//  test
//
//  Created by 李彦宏 on 2018/3/13.
//  Copyright © 2018年 朱圳. All rights reserved.
//课酬未打款

#import "GRCouseFeeMainVC.h"
#import "JWGRKCcell.h"//课酬cell
#import "NewLecturTableHead.h"//section==0头
#import "GRCouseWFVC.h"//查看详情
#import "JWKCFeemodel.h"//课酬model
@interface GRCouseFeeMainVC ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) JWKCFeemodel *model;
@property (nonatomic, strong) NSMutableArray *contArry;
@end

@implementation GRCouseFeeMainVC

//UItableView初始化
- (void)setupTable
{
    UITableView *tableView=[[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    //隐藏组距导航栏的间距
    tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, CGFLOAT_MIN)];
    tableView.backgroundColor=[UIColor whiteColor];
    tableView.showsHorizontalScrollIndicator=NO;
    tableView.showsVerticalScrollIndicator=NO;
    tableView.dataSource=self;
    tableView.delegate=self;
    //自适应cell
    tableView.estimatedRowHeight = 120;
    tableView.rowHeight = UITableViewAutomaticDimension; tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
    [self.view addSubview:tableView];
    self.tableView=tableView;
    
    
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [EasyShowOptions sharedEasyShowOptions].lodingShowType =  LodingShowTypeTurnAround ;
    [EasyShowOptions sharedEasyShowOptions].textStatusType =  ShowTextStatusTypeStatusBar ;
    [EasyShowLodingView showLodingText:@""];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self setdata];
        [EasyShowLodingView hidenLoding];
    });
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupTable];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
}

#pragma -mark -----------------------------tableview datasource and delegate---------------------------------
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.contArry.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 45;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    JWGRKCcell *cell=[JWGRKCcell cellwithTableview:tableView];
    
    cell.model=self.contArry[indexPath.row];
    
    [cell.KCcondPayBtn setTitle:@"查看详情" forState:UIControlStateNormal];
    
    [cell setAddImageBlock:^{
        NSUInteger teger=indexPath.row;
        NSLog(@"--走看详情去》〉去-teger--%lu", teger);
        self.model=self.contArry[indexPath.row];
        GRCouseWFVC *vc=[[GRCouseWFVC alloc]init];
        vc.arry=[[NSMutableArray alloc]init];
        [vc.arry addObject:self.model];
        vc.title=@"查看详情";
        vc.view.backgroundColor=[UIColor whiteColor];
        [self.navigationController pushViewController:vc animated:YES];
        
    }];
    cell.selectionStyle=UITableViewCellSelectionStyleNone;
    return cell;
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 40;
}


- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 1;
}

#pragma -mark 头部的内容
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    NewLecturTableHead *header=[[NewLecturTableHead alloc]init];
    
    return header;
    
}
#pragma -mark ———————————————课酬数据————————————————————
-(void)setdata{
    NSDictionary *dic=@{
                        @"gid" : Gid,
                        @"gpass" : Gpassword,
                        };
    NSLog(@"--dic--%@", dic);
    [[AFNetworkTool shareManager]postJSONWithUrl:GR_KeCoulist parmas:dic successData:^(id json) {
        [self.contArry removeAllObjects];
        NSArray *arry=json[@"list"];
        for(int i=0;i<arry.count;i++){
            self.model=[JWKCFeemodel yy_modelWithJSON:arry[i]];
            
            [self.contArry addObject:self.model];
            
        }
        
        __weak typeof(self) weakslf = self;
        dispatch_async(dispatch_get_main_queue(), ^{
            
            NSInteger cout=self.contArry.count;
            if(cout==0){
                [self.tableView removeFromSuperview];
                KongDataView *konview=[KongDataView NilDataview];
                konview.frame=self.view.frame;
                [self.view addSubview:konview];
            }
            [weakslf.tableView reloadData];
        });
        
    } failure:^(NSError *error) {
        NSLog(@"--error--%@", error);
    }];
    
}
-(NSMutableArray*)contArry{
    if(_contArry==nil){
        _contArry=[[NSMutableArray alloc]init];
    }
    return _contArry;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
